package com.shop2cn.iapi.agentproducts.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.AddConditionRebateBean;
import com.shop2cn.iapi.agentproducts.parameter.EditProductRebateBean;
import com.shop2cn.iapi.agentproducts.parameter.GetProductRebateBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.shop2cn.iapi.agentproducts.service.GetProductRebateCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
/**
*商品分佣详情Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetProductRebate{
	private static GetProductRebateBean getproductrebateBean;
	private static GetProductRebateCall getproductrebateCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商品分佣详情Test");
	}

	@Before
	public void caseUp() {
		getproductrebateBean=new GetProductRebateBean();
		getproductrebateCall=new GetProductRebateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getproductrebateCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductRebate_001() {
		Logger.start(true,"查询根据商品设置分佣，成功");
		try {
			//创建一个商户和分销小店
			Integer userId = GodmchManageCallService.CreateGodMch();
			Integer StoreId = GodmchManageCallService.CreateStores(userId, 20);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			double RebateValue=new Double("0."+TestDataManager.getRandomIntNum(2));
			EditProductRebateBean initEditProductRebateBean = AddAgentProductCallService.initEditProductRebateBean(productId, StoreId, userId, RebateValue);
			 AddAgentProductCallService.EditProductRebateBean(initEditProductRebateBean);
			 
			getproductrebateBean.setProductId(productId);
			getproductrebateBean.setUserId(userId);
			getproductrebateCall.setData(getproductrebateBean);
			getproductrebateCall.callService();
			Logger.verifyEquals("200", getproductrebateCall.getString("code"), "验证code");
			JsonObject data = getproductrebateCall.getJsonObject().getAsJsonObject("data");
			Logger.verifyEquals(1,data.get("rebateType").getAsInt(), "验证分佣方式");
			Logger.verifyEquals(RebateValue,data.getAsJsonArray("detailCatalogRebateList").get(0).getAsJsonObject().get("rebateValue").getAsDouble(), "验证佣金是否设置正确");
			Logger.verifyEquals(RebateValue,data.getAsJsonArray("detailCatalogRebateList").get(0).getAsJsonObject().get("rebateValue").getAsDouble(), "验证佣金是否设置正确");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductRebate_002() {
		Logger.start(true,"查询根据商品设置分佣，成功");
		try {
			//创建一个商户和分销小店
			Integer userId = GodmchManageCallService.CreateGodMch();
			Integer StoreId = GodmchManageCallService.CreateStores(userId, 20);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			double RebateValue=new Double("0."+TestDataManager.getRandomIntNum(2));
			EditProductRebateBean initEditProductRebateBean = AddAgentProductCallService.initEditProductRebateBean(productId, StoreId, userId, RebateValue);
			 AddAgentProductCallService.EditProductRebateBean(initEditProductRebateBean);
			 
			getproductrebateBean.setProductId(productId);
			getproductrebateBean.setUserId(userId);
			getproductrebateCall.setData(getproductrebateBean);
			getproductrebateCall.callService();
			Logger.verifyEquals("200", getproductrebateCall.getString("code"), "验证code");
			JsonObject data = getproductrebateCall.getJsonObject().getAsJsonObject("data");
			Logger.verifyEquals(1,data.get("rebateType").getAsInt(), "验证分佣方式");
			Logger.verifyEquals(RebateValue,data.getAsJsonArray("detailCatalogRebateList").get(0).getAsJsonObject().get("rebateValue").getAsDouble(), "验证佣金是否设置正确");
			Logger.verifyEquals(RebateValue,data.getAsJsonArray("detailCatalogRebateList").get(0).getAsJsonObject().get("rebateValue").getAsDouble(), "验证佣金是否设置正确");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}